package cn.tedu.thread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
/**单线程的定时任务调度*/
public class TimerTests {
    public static void main(String[] args) throws ParseException {
        Timer timer = new Timer();//构建一个线程，同时创建一个任务队列
        //单线程任务调度
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("task1:"+System.currentTimeMillis());
            }
        },1000,2000);

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String time="2024/08/06 11:31:00";
        Date parse = sdf.parse(time);
        System.out.println("time:"+parse);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("task2:"+System.currentTimeMillis());
            }
        },parse,24*3600*1000);

    }
}
